package org.manon.json.filter;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


public final class FilterBuilder {

	private final Map<String,Set<String>> _pojoFilters = new HashMap<String, Set<String>>();
	
	public FilterBuilder add(String pojo,String ... properties) {
		_pojoFilters.put(pojo, convert(properties));
		return this;
	}
	
	public FilterBuilder addAll(String pojo) {
		_pojoFilters.put(pojo, BasicSet.TRUE);
		return this;
	}
	
	public FilterBuilder addAllExcept(String pojo,String ... properties) {
		_pojoFilters.put(pojo, BasicSet.createExceptSet(convert(properties)));
		return this;
	}

	private Set<String> convert(String[] properties) {
		final Set<String> set = new HashSet<String>();
		for (String property : properties) {
			set.add(property);
		}
		return Collections.unmodifiableSet(set);
	}
	
	public Filter build() {
		return new InteralFilter();
	}
	
	
	private final class InteralFilter implements Filter {
		/**
		 * @see org.manon.json.filter.Filter#getProperties(java.lang.String)
		 */
		public Set<String> getProperties(String pojo) {
			return _pojoFilters.get(pojo);
		}
	}
	
}
